/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wf3.gps;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.awt.image.FilteredImageSource;
import java.awt.image.ImageFilter;
import java.awt.image.ImageProducer;
import java.awt.image.RGBImageFilter;

/**
 *
 * @author john
 */
public class ClusterIconChange {

    private BufferedImage img;
    private int red = Color.RED.getRGB();
    private Color color;

    public ClusterIconChange(BufferedImage img, Color color) {
        this.img = img;
        this.color = color;
    }
    ImageFilter filter = new RGBImageFilter() {
        @Override
        public int filterRGB(int x, int y, int rgb) {
            return rgb & 0xff000000 | color.getRed() << 16 | color.getGreen() << 8 | color.getBlue();
        }
    };

    public BufferedImage cambiarColor() {
        BufferedImage imgDestination;

        ImageProducer ip = new FilteredImageSource(img.getSource(), filter);
        Image img = Toolkit.getDefaultToolkit().createImage(ip);
        imgDestination = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB);
        Graphics2D g2dImg = imgDestination.createGraphics();
        g2dImg.drawImage(img, 0, 0, null);
        g2dImg.dispose();
        return imgDestination;
    }
}
